<div class="SipeiMain_r fr">
    <h2 class="clearfix fonts_18 height45 fontc_444"><?php echo $this->title; ?></h2>
    <ul class="clearfix back_bgf border_3 border_c pr30 pl30 pt20 pb20 height32 fontc_666">
        <form action="<?php echo $this->createUrl('/role/default/index'); ?>" method="get" name="search">
            <li class="fl pt10 pr30 pb10">
                角色代码：<input type="text" name="role_code" value="<?php echo isset($search['role_code'])?$search['role_code']:''; ?>" class="pt6 pr9 pb6 pl9 border_3 border_c fontc_666 w100" />
            </li>
            <li class="fl pt10 pr30 pb10">
                角色名称：<input type="text" name="role_name" value="<?php echo isset($search['role_name'])?$search['role_name']:''; ?>" class="pt6 pr9 pb6 pl9 border_3 border_c fontc_666 w100" />
            </li>
            <!--<li class="fl pt10 pr30 pb10"><span class="fl pr8">是否生效</span><input type="checkbox" name="status" checked="checked" class="fl mt9" /></li>-->
            <li class="fr pt10 pb10"><input type="submit" value="查询" class="b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" /></li>
        </form>
    </ul>
    <div class="clearfix back_bgf border_c mt15 pt20 pb20">
        <div class="clearfix pb20 pl30">
            <input type="button" value="新增" style="margin-right:30px;" class="fr b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 add_role cursor" />
        </div>
        <table class="height40">
            <thead class="back_bgf5 fontc_666">
                <tr>
                    <th width="139" align="center" class="m_hr_t m_hr_b">角色代码</th>
                    <th width="230" align="center" class="m_hr_t m_hr_b pl30">用户角色</th>
                    <th width="230" align="center" class="m_hr_t m_hr_b">拥有权限</th>
                    <th width="440" align="left" class="m_hr_t m_hr_b pl20">备注</th>
                    <th width="146" align="center" class="m_hr_t m_hr_b">操作</th>
                </tr>
            </thead>
            <tbody class="fontc_444">
                <?php if(!empty($data)): ?>
                <?php   foreach($data as $value): ?>
                <tr>
                    <td align="center" class="m_hr_b"><?php echo $value['role_code']; ?></td>
                    <td align="center" class="m_hr_b pl30"><?php echo $value['role_name']; ?></td>
                    <td align="center" class="m_hr_b">
                        <a href="javascript:;" role_id="<?php echo $value['role_id']; ?>" class="role_priv"><font class="fontc_444">拥有权限</font></a>
                    </td>
                    <td align="left" class="m_hr_b pl20"><?php echo $value['description'];?></td>
                    <td align="center" class="m_hr_b">
                        <?php if($value['role_id']!=1): ?>
                        <a href="javascript:;" onclick="edit(<?php echo $value['role_id']; ?>)" title="编辑" class="mr10">
                            <img src="/themes/default/images/Sipei/edit.png" />
                        </a>
                        <a href="javascript:;" onclick="del(<?php echo $value['role_id']; ?>,$(this))" title="删除">
                            <img src="/themes/default/images/Sipei/delate.png" />
                        </a>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php   endforeach; ?>
                <?php else: ?>
                <tr><td colspan="8" align="center" class="m_hr_b">暂时没有角色信息</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
        <?php $this->renderPartial('//partial/partial_pager', array('pages' => $pages, "url" => $pageUrl)); ?>
    </div>
</div>
<script type="text/javascript">
    function edit(id) {
        api = $.dialog({
            id: 'testID2',
            lock: true,
            fixed: true,
            title:"编辑",
            width:580,
            height:520,
            max: false,
            min: false
        });

        $.post('/role/default/upd_priv',{rid:id,time:new Date()},function(html){
            api.content(html);
        });
    }
    
    $(".add_role").click(function(){       
        api = $.dialog({
            id: 'testID2',
            lock: true,
            fixed: true,
            title:"新增",
            width:580,
            height:380,
            max: false,
            min: false
        });

        $.post('/role/default/add_role',{},function(html){
            api.content(html);
        });
    });
    
    function del(id,that){
        $.dialog.confirm('确定删除吗',function(){
            $.get('/role/default/delete',{id:id},function(html){
                if(html==1){
                    that.parents('tr').remove();
                }else if(html == 2){
                    $.dialog.alert('该角色下已有用户,不允许删除');
                }else{
                    $.dialog.alert("删除失败");
                }
            });
        });
    }
    
    $(".role_priv").click(function(){
        var role_id = $(this).attr('role_id');
        api = $.dialog({
            id: 'testID2',
            lock: true,
            fixed: true,
            title:"功能权限",
            width:580,
            height:520,
            max: false,
            min: false
        });
        $.post('/role/default/prive',{role_id:role_id,time:new Date()},function(html){
            api.content(html);
        });
    });
</script>